﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using RssWindowsPhone.ServiceReference;

namespace RssWindowsPhone
{
    public partial class Register : PhoneApplicationPage
    {
        public Register()
        {
            InitializeComponent();
        }

        private void registerBtn_Click(object sender, RoutedEventArgs e)
        {
            ServiceRssClient client = new ServiceRssClient();

            RegisterModel register = new RegisterModel()
            {
                UserName = this.registerLoginBox.Text,
                Password = this.registerPasswordBox.Password,
                ConfirmPassword = this.registerPasswordVerifyBox.Password
            };

            client.CreatAccountAndConnectAsync(register);
            client.CreatAccountAndConnectCompleted += new EventHandler<CreatAccountAndConnectCompletedEventArgs>(client_CreatAccountAndConnectCompleted);

        }

        void client_CreatAccountAndConnectCompleted(object sender, CreatAccountAndConnectCompletedEventArgs e)
        {
            MembershipCreateStatus status = e.Result;

            if (status == MembershipCreateStatus.Success)
                NavigationService.Navigate(new Uri("/CoreApp.xaml?User=" + this.registerLoginBox.Text + "&Password=" + this.registerPasswordBox.Password, UriKind.Relative));
            else
                this.registerErrorMsg.Text = status.ToString();
        }
    }
}